package com.runing.controller;


import com.runing.config.ResponseWrapper;
import com.runing.entity.RStatistic;
import com.runing.service.impl.RStatisticServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.text.ParseException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lel
 * @since 2021-03-11
 */
@RestController
@RequestMapping("/rStatistic")
@Api(tags = "跑步记录")
public class RStatisticController {

    @Autowired
    RStatisticServiceImpl statisticService;

    @ApiOperation("获取当前周的跑步记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sid",value = "学生id"),
            @ApiImplicitParam(name = "wid",value = "当前周id")
    })
    @GetMapping("/RunRecord")
    public ResponseWrapper runRecord(@RequestParam(name="sid")Integer sid,
                                     @RequestParam(name="wid")Integer wid){
        ResponseWrapper wrapper = statisticService.runRecord(sid,wid);
        return wrapper;
    }
    @ApiOperation("判断是否在规定时间")
    @GetMapping("/inTime")
    public ResponseWrapper inTime() throws ParseException {
        ResponseWrapper wrapper = statisticService.inTime();
        return wrapper;
    }
    @ApiOperation("增加跑步记录")
    @PostMapping("/addStatisic")
    public ResponseWrapper addStatisic(@RequestHeader(name = "ssid",required = false)String ssid,
                                       @RequestHeader(name = "latitude",required = false)String latitude,
                                       @RequestHeader(name = "longitude",required = false)String longitude,
                                       @RequestBody RStatistic rStatistic) throws ParseException {
        ResponseWrapper wrapper = statisticService.addStatisic(latitude,longitude,ssid,rStatistic);
        return wrapper;
    }

    @ApiOperation("查某周的跑步记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sid",value = "学生id"),
            @ApiImplicitParam(name = "wid",value = "当前周id")
    })
    @GetMapping("/getRunningData")
    public ResponseWrapper getRunningData(@RequestParam(name = "sid")Integer sid,
                                          @RequestParam(name = "wid")Integer wid){
        ResponseWrapper wrapper = statisticService.nowRSatistic(sid,wid);
        return wrapper;
    }
    @ApiOperation("某学期的跑步记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sid",value = "学生id"),
            @ApiImplicitParam(name = "seid",value = "学期id"),
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "页码数",defaultValue = "1")
    })
    @GetMapping("/getStatisticByClid")
    public ResponseWrapper getStatisticByClid(@RequestParam(name = "sid")Integer sid,
                                              @RequestParam(name = "seid")Integer seid,
                                              @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                              @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum){
        ResponseWrapper wrapper = statisticService.getStatisticByClid(sid,seid,pageSize,pageNum);
        return wrapper;
    }
    @ApiOperation("查某学期的跑步记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sid",value = "学生id"),
            @ApiImplicitParam(name = "seid",value = "学期id"),
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "页码数",defaultValue = "1")
    })
    @GetMapping("/getStatistic")
    public ResponseWrapper getStatistic(@RequestParam(name = "sid")Integer sid,
                                              @RequestParam(name = "seid")Integer seid,
                                              @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                              @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum){
        ResponseWrapper wrapper = statisticService.getStatistic(sid,seid,pageSize,pageNum);
        return wrapper;
    }

    @ApiOperation("按周次和班级查询跑步情况（画图）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wid",value = "周次id"),
            @ApiImplicitParam(name = "clid",value = "班级id")
    })
    @GetMapping("/getSta")
    public ResponseWrapper getSta(@RequestParam(name = "wid")Integer wid,
                                  @RequestParam(name = "clid")Integer clid){
        ResponseWrapper wrapper = statisticService.getSta(clid,wid);
        return wrapper;
    }

    @ApiOperation("移动端首页，获取目标和本周次数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sid",value = "学生id"),
            @ApiImplicitParam(name = "wid",value = "当前周id")
    })
    @GetMapping("/nowWeekSta")
    public ResponseWrapper nowWeekSta(@RequestParam(name = "sid")Integer sid,
                                          @RequestParam(name = "wid")Integer wid){
        ResponseWrapper wrapper = statisticService.nowWeekSta(sid,wid);
        return wrapper;
    }
}

